/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/
package xxhci.oracle.apps.XXIERP.TrainingEvoluation.webui;

import com.sun.java.util.collections.HashMap;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;


import java.io.Serializable;

import java.sql.SQLException;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.apps.fnd.framework.webui.beans.form.OASubmitButtonBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageDateFieldBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageRadioButtonBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;

import oracle.jbo.Row;

import oracle.jbo.domain.Date;
import oracle.jbo.domain.Number;


/**
 * Controller for ...
 */
public class xxierptrainingevalCreateCO extends OAControllerImpl {
    public static final String RCS_ID = "$Header$";
    public static final boolean RCS_ID_RECORDED = 
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

    /**
     * Layout and page setup logic for a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processRequest(OAPageContext pageContext, OAWebBean webBean) {


        super.processRequest(pageContext, webBean);
        String paramReqNo = pageContext.getParameter("xxierpParamReqNo");
        String paramAction = pageContext.getParameter("xxierpParamAction");
        String paramPersonId = pageContext.getParameter("xxierpParamPersonId");
        String paramStatusId = pageContext.getParameter("xxierpParamStatusId");
        String paramStatus = pageContext.getParameter("xxierpParamStatus");
        String paramEmpdesg = pageContext.getParameter("xxierpParamEmpDesg");
        OAApplicationModule am = pageContext.getApplicationModule(webBean);

        String ConfMesg = "";
        if (pageContext.getParameter("paramAction") != null)
            paramAction = pageContext.getParameter("xxierpParamAction");


        Serializable[] initParams = { pageContext.getUserName().toString(), Date.getCurrentDate().toString() };

        // { pageContext.getUserName().toString()};

        am.invokeMethod("getEmpDetails", initParams);
        OAViewObject empVO = 
            (OAViewObject)am.findViewObject("xxierptrainingevalEmpDetVO1");
        Row row[] = empVO.getAllRowsInRange();
        // To Display Items from EmpDetailsVO  

        // Number EmpId = new Number(row[0].getAttribute("EmployeeNumber"));

        Number PerId = (Number)row[0].getAttribute("PersonId");
        Number DepId = (Number)row[0].getAttribute("DeptId");
        String Designation = (String)row[0].getAttribute("Designation");
        System.out.println("DepId         " + DepId);
        // am.invokeMethod("createEvoluationMethod");


        //radio part common
        getEvaluationDetails(webBean);

        if (paramAction.equalsIgnoreCase("viewRequest")) {

            Serializable ReqNoParamList[] = { paramReqNo };


            am.invokeMethod("UpdateMethod", ReqNoParamList);
            ConfMesg = "Training Evoluation Request Saved Successfully.";

            // OAViewObject evalVO = (OAViewObject)am.findViewObject("xxierptrainingevalVO1");
            //Row row1[] = evalVO.getAllRowsInRange();

            //            if(row1[0].getAttribute("TrngEvalQ1a1")!=null)
            //            {
            //            System.out.println("sssssssssssssssssssssssssssssssssssssssssssss"+row1[0].getAttribute("TrngEvalQ1a1"));
            //               OAMessageRadioButtonBean rdBtn=(OAMessageRadioButtonBean) webBean.findChildRecursive("Q1A"+row1[0].getAttribute("TrngEvalQ1a1").toString());
            //               rdBtn.setSelected(true);
            //            }
            //radio part
            OAMessageTextInputBean StatusId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
            StatusId.setValue(pageContext, paramStatusId);

            // if(empVO.getRowCount()!=0)
            // {
            OAMessageTextInputBean EmployeeId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("EmployeeId");
            EmployeeId.setValue(pageContext, PerId);

            OAMessageTextInputBean Desig = 
                (OAMessageTextInputBean)webBean.findChildRecursive("PositionDesignation");
            Desig.setValue(pageContext, Designation);


            OAMessageTextInputBean DepartmentId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("DepartmentId");
            DepartmentId.setValue(pageContext, DepId);


            if (!paramStatusId.equalsIgnoreCase("TE01")) {
                OASubmitButtonBean btnSave = 
                    (OASubmitButtonBean)webBean.findChildRecursive("btnSave");
                btnSave.setRendered(false);
                OASubmitButtonBean btnSubmit = 
                    (OASubmitButtonBean)webBean.findChildRecursive("btnApply");
                btnSubmit.setRendered(false);

                OAMessageTextInputBean CourseName = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("CourseName");
                CourseName.setReadOnly(true);

                OAMessageDateFieldBean CourseDate = 
                    (OAMessageDateFieldBean)webBean.findChildRecursive("CourseDate");
                CourseDate.setReadOnly(true);

       /*                       Q1A1.setReadOnly(true);
                                Q1A2.setReadOnly(true);
                                Q1A3.setReadOnly(true);
                                Q1A4.setReadOnly(true);
                                ExtremelyWell.setReadOnly(true);
                                Q2_Notatall.setReadOnly(true);
                                Q2_1.setReadOnly(true);
                                Q2_2.setReadOnly(true);
                                Q2_3.setReadOnly(true);
                                Q2_4.setReadOnly(true);
                                Q2_5.setReadOnly(true);
                                Q2_6.setReadOnly(true);
                                Veryhigh.setReadOnly(true);
                                NoSupport.setReadOnly(true);
                                Q3_1.setReadOnly(true);
                                Q3_2.setReadOnly(true);
                                Q3_3.setReadOnly(true);
                                Q3_4.setReadOnly(true);
                                Q3_5.setReadOnly(true);
                                Q3_6.setReadOnly(true);
                                VerySatisfied.setReadOnly(true);
                                Satisfied.setReadOnly(true);
                                Neutral.setReadOnly(true);
                                Dissatisfied.setReadOnly(true);
                                Q6_1_Yes.setReadOnly(true);
                                Q6_1_No.setReadOnly(true);
                
                                Q6_2_Yes.setReadOnly(true);
                                Q6_2_No.setReadOnly(true);
                
                                Q6_3_Yes.setReadOnly(true);
                                Q6_3_No.setReadOnly(true);
                
                                Q6_4_Yes.setReadOnly(true);
                                Q6_4_No.setReadOnly(true);
                
                                Q6_5_Yes.setReadOnly(true);
                                Q6_5_No.setReadOnly(true);
                
                                Q6_6_Yes.setReadOnly(true);
                                Q6_6_No.setReadOnly(true);
                
                
                                WE_Yes.setReadOnly(true);
                                WE_No.setReadOnly(true);
                
                                LM_Yes.setReadOnly(true);
                                LM_No.setReadOnly(true);  */


                OAMessageTextInputBean Q1addcom = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("Q1addcom");
                Q1addcom.setReadOnly(true);
                OAMessageTextInputBean AddCommentsQ2 = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("AddCommentsQ2");
                AddCommentsQ2.setReadOnly(true);
                OAMessageTextInputBean AddCommentQ3 = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("AddCommentQ3");
                AddCommentQ3.setReadOnly(true);
                OAMessageTextInputBean Q5_1 = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("Q5_1");
                Q5_1.setReadOnly(true);
                OAMessageTextInputBean place_Q6 = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("place_Q6");
                place_Q6.setReadOnly(true);
                OAMessageTextInputBean methods_Q6 = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("methods_Q6");
                methods_Q6.setReadOnly(true);
                OAMessageTextInputBean Q7_1 = 
                    (OAMessageTextInputBean)webBean.findChildRecursive("Q7_1");
                Q7_1.setReadOnly(true);


            }


        } else {


            // am.invokeMethod("createEmployee");
            am.invokeMethod("createEvoluationMethod");
            OAMessageTextInputBean StatusId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
            StatusId.setValue(pageContext, paramStatusId);

            OAMessageTextInputBean StatusDesc = 
                (OAMessageTextInputBean)webBean.findChildRecursive("Description");
            StatusDesc.setValue(pageContext, paramStatus);


            OAMessageTextInputBean EmployeeId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("EmployeeId");
            EmployeeId.setValue(pageContext, PerId);

            OAMessageTextInputBean Desig = 
                (OAMessageTextInputBean)webBean.findChildRecursive("PositionDesignation");
            Desig.setValue(pageContext, Designation);


            OAMessageTextInputBean DepartmentId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("DepartmentId");
            DepartmentId.setValue(pageContext, DepId);


        }


    }


    /**
     * Procedure to handle form submissions for form elements in
     * a region.
     * @param pageContext the current OA page context
     * @param webBean the web bean corresponding to the region
     */
    public void processFormRequest(OAPageContext pageContext, 
                                   OAWebBean webBean) {
        super.processFormRequest(pageContext, webBean);
        OAApplicationModule am = pageContext.getApplicationModule(webBean);
        String ConfMesg = "";
        if ("saveTraningEval".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {
            System.out.println("apply in saveTrainingEval");
            am.invokeMethod("apply");
                        System.out.println("apply in saveTrainingEval2");
                        ConfMesg = "Training Evoluation Saved Successfully.";
                        HashMap phm = new HashMap();
                        phm.put("xxierpRequestConfMesg", ConfMesg);
                        pageContext.setForwardURL("OA.jsp?page=/xxhci/oracle/apps/XXIERP/TrainingEvoluation/webui/xxierptrainingevalSearchPG", 
                                                  null, 
                                                  OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                                  null, phm, true, 
                                                  OAWebBeanConstants.ADD_BREAD_CRUMB_YES, 
                                                  OAWebBeanConstants.IGNORE_MESSAGES);
        }

        else if ("submitRequest".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM))) {
            OAMessageTextInputBean StatusId = 
                (OAMessageTextInputBean)webBean.findChildRecursive("StatusId");
            StatusId.setValue(pageContext, "TE02");
            
            OAMessageTextInputBean Description=(OAMessageTextInputBean)webBean.findChildRecursive("Description");
            Description.setValue(pageContext,"Submitted");
            am.invokeMethod("apply");
                        ConfMesg = "Training Evoluation Submitted Successfully.";
                        HashMap phm = new HashMap();
                        phm.put("xxierpRequestConfMesg", ConfMesg);
                        pageContext.setForwardURL("OA.jsp?page=/xxhci/oracle/apps/XXIERP/TrainingEvoluation/webui/xxierptrainingevalSearchPG", 
                                                  null, 
                                                  OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                                  null, phm, true, 
                                                  OAWebBeanConstants.ADD_BREAD_CRUMB_YES, 
                                                  OAWebBeanConstants.IGNORE_MESSAGES);


        } else if (pageContext.getParameter("event").equalsIgnoreCase("Cancel")) {
            am.invokeMethod("rollbackEmployee");
            pageContext.forwardImmediately("OA.jsp?page=/xxhci/oracle/apps/XXIERP/TrainingEvoluation/webui/xxierptrainingevalSearchPG", 
                                           null, 
                                           OAWebBeanConstants.KEEP_MENU_CONTEXT, 
                                           null, null, false, 
                                           OAWebBeanConstants.ADD_BREAD_CRUMB_NO);

        }


    }

    private void getEvaluationDetails(OAWebBean webBean) {
        System.out.println("Radio common is calling");
        OAMessageRadioButtonBean Q1A1 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q1A1"); //First Radio Button   
        Q1A1.setName("rdoGrpQ1");
        Q1A1.setValue("1");

        OAMessageRadioButtonBean Q1A2 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q1A2"); //Second Radio Button   
        Q1A2.setName("rdoGrpQ1");
        Q1A2.setValue("2");

        OAMessageRadioButtonBean Q1A3 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q1A3"); //Third Radio Button   
        Q1A3.setName("rdoGrpQ1");
        Q1A3.setValue("3");

        OAMessageRadioButtonBean Q1A4 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q1A4"); //Fourth Radio Button   
        Q1A4.setName("rdoGrpQ1");
        Q1A4.setValue("4");
        //Radio button part for Question2   
        OAMessageRadioButtonBean ExtremelyWell = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("ExtremelyWell"); //First Radio Button   
        ExtremelyWell.setName("RdoGrpQ2");
        ExtremelyWell.setValue("1");

        OAMessageRadioButtonBean Q2_Notatall = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q2_Notatall"); //Second Radio Button   
        Q2_Notatall.setName("RdoGrpQ2");
        Q2_Notatall.setValue("2");
        //Q2 rating starts here
        OAMessageRadioButtonBean Q2_1 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q2_1"); //Third Radio Button   
        Q2_1.setName("RdoGrpQ2Rating");
        Q2_1.setValue("1");
        OAMessageRadioButtonBean Q2_2 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q2_2"); //Fourth Radio Button   
        Q2_2.setName("RdoGrpQ2Rating");
        Q2_2.setValue("2");

        OAMessageRadioButtonBean Q2_3 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q2_3"); //Third Radio Button
        Q2_3.setName("RdoGrpQ2Rating");
        Q2_3.setValue("3");
        OAMessageRadioButtonBean Q2_4 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q2_4"); //Fourth Radio Button
        Q2_4.setName("RdoGrpQ2Rating");
        Q2_4.setValue("4");

        OAMessageRadioButtonBean Q2_5 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q2_5"); //Third Radio Button
        Q2_5.setName("RdoGrpQ2Rating");
        Q2_5.setValue("5");
        OAMessageRadioButtonBean Q2_6 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q2_6"); //Fourth Radio Button
        Q2_6.setName("RdoGrpQ2Rating");
        Q2_6.setValue("6");

        //Radio button part for Question 3   
        OAMessageRadioButtonBean Veryhigh = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Veryhigh"); //First Radio Button   
        Veryhigh.setName("RdoGrpQ3");
        Veryhigh.setValue("1");

        OAMessageRadioButtonBean NoSupport = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("NoSupport"); //Second Radio Button   
        NoSupport.setName("RdoGrpQ3");
        NoSupport.setValue("2");
        //Q2 rating starts here
        OAMessageRadioButtonBean Q3_1 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q3_1"); //Third Radio Button   
        Q3_1.setName("RdoGrpQ3Rating");
        Q3_1.setValue("1");
        OAMessageRadioButtonBean Q3_2 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q3_2"); //Fourth Radio Button   
        Q3_2.setName("RdoGrpQ3Rating");
        Q3_2.setValue("2");

        OAMessageRadioButtonBean Q3_3 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q3_3"); //Third Radio Button
        Q3_3.setName("RdoGrpQ3Rating");
        Q3_3.setValue("3");
        OAMessageRadioButtonBean Q3_4 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q3_4"); //Fourth Radio Button
        Q3_4.setName("RdoGrpQ3Rating");
        Q3_4.setValue("4");

        OAMessageRadioButtonBean Q3_5 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q3_5"); //Third Radio Button
        Q3_5.setName("RdoGrpQ3Rating");
        Q3_5.setValue("5");
        OAMessageRadioButtonBean Q3_6 = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q3_6"); //Fourth Radio Button
        Q3_6.setName("RdoGrpQ3Rating");
        Q3_6.setValue("6");

        //Radio button part for Question 4       

        OAMessageRadioButtonBean VerySatisfied = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("VerySatisfied"); //First Radio Button   
        VerySatisfied.setName("RdoGrpQ4");
        VerySatisfied.setValue("1");

        OAMessageRadioButtonBean Satisfied = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Satisfied"); //Second Radio Button   
        Satisfied.setName("RdoGrpQ4");
        Satisfied.setValue("2");

        OAMessageRadioButtonBean Neutral = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Neutral"); //Third Radio Button   
        Neutral.setName("RdoGrpQ4");
        Neutral.setValue("3");
        OAMessageRadioButtonBean Dissatisfied = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Dissatisfied"); //Fourth Radio Button   
        Dissatisfied.setName("RdoGrpQ4");
        Dissatisfied.setValue("4");


        //Radio button part for Question 6_1     

        OAMessageRadioButtonBean Q6_1_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_1_Yes"); //First Radio Button   
        Q6_1_Yes.setName("RdoGrpQ6_1");
        Q6_1_Yes.setValue("1");

        OAMessageRadioButtonBean Q6_1_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_1_No"); //Second Radio Button   
        Q6_1_No.setName("RdoGrpQ6_1");
        Q6_1_No.setValue("2");

        //Radio button part for Question 6_2     

        OAMessageRadioButtonBean Q6_2_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_2_Yes"); //First Radio Button   
        Q6_2_Yes.setName("RdoGrpQ6_2");
        Q6_2_Yes.setValue("1");

        OAMessageRadioButtonBean Q6_2_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_2_No"); //Second Radio Button   
        Q6_2_No.setName("RdoGrpQ6_2");
        Q6_2_No.setValue("2");

        //Radio button part for Question 6_3     

        OAMessageRadioButtonBean Q6_3_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_3_Yes"); //First Radio Button   
        Q6_3_Yes.setName("RdoGrpQ6_3");
        Q6_3_Yes.setValue("1");

        OAMessageRadioButtonBean Q6_3_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_3_No"); //Second Radio Button   
        Q6_3_No.setName("RdoGrpQ6_3");
        Q6_3_No.setValue("2");


        //Radio button part for Question 6_4     

        OAMessageRadioButtonBean Q6_4_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_4_Yes"); //First Radio Button   
        Q6_4_Yes.setName("RdoGrpQ6_4");
        Q6_4_Yes.setValue("1");

        OAMessageRadioButtonBean Q6_4_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_4_No"); //Second Radio Button   
        Q6_4_No.setName("RdoGrpQ6_4");
        Q6_4_No.setValue("2");


        //Radio button part for Question 6_5     

        OAMessageRadioButtonBean Q6_5_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_5_Yes"); //First Radio Button   
        Q6_5_Yes.setName("RdoGrpQ6_5");
        Q6_5_Yes.setValue("1");

        OAMessageRadioButtonBean Q6_5_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_5_No"); //Second Radio Button   
        Q6_5_No.setName("RdoGrpQ6_5");
        Q6_5_No.setValue("2");


        //Radio button part for Question 6_6     

        OAMessageRadioButtonBean Q6_6_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_6_Yes"); //First Radio Button   
        Q6_6_Yes.setName("RdoGrpQ6_6");
        Q6_6_Yes.setValue("1");

        OAMessageRadioButtonBean Q6_6_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("Q6_6_No"); //Second Radio Button   
        Q6_6_No.setName("RdoGrpQ6_6");
        Q6_6_No.setValue("2");

        //Radio button part for Question 6_6a     

        OAMessageRadioButtonBean WE_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("WE_Yes"); //First Radio Button   
        WE_Yes.setName("RdoGrpWellEquipped");
        WE_Yes.setValue("1");

        OAMessageRadioButtonBean WE_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("WE_No"); //Second Radio Button   
        WE_No.setName("RdoGrpWellEquipped");
        WE_No.setValue("2");

        //Radio button part for Question 6_6b     

        OAMessageRadioButtonBean LM_Yes = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("LM_Yes"); //First Radio Button   
        LM_Yes.setName("RdoGrpearningMaterials");
        LM_Yes.setValue("1");

        OAMessageRadioButtonBean LM_No = 
            (OAMessageRadioButtonBean)webBean.findChildRecursive("LM_No"); //Second Radio Button   
        LM_No.setName("RdoGrpearningMaterials");
        LM_No.setValue("2");
    }
}
